<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.xmpp.event &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="up" title="gozerlib.xmpp" href="index.html" />
    <link rel="next" title="gcalc" href="../../waveplugs/gcalc.html" />
    <link rel="prev" title="gozerlib.xmpp.bot" href="bot.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="../../waveplugs/gcalc.html" title="gcalc"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="bot.html" title="gozerlib.xmpp.bot"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">gozerlib.xmpp</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.xmpp.event">
<h1>gozerlib.xmpp.event<a class="headerlink" href="#module-gozerlib.xmpp.event" title="Permalink to this headline">¶</a></h1>
<p>an xmpp event.</p>
<dl class="class">
<dt id="gozerlib.xmpp.event.XMPPEvent">
<em class="property">class </em><tt class="descclassname">gozerlib.xmpp.event.</tt><tt class="descname">XMPPEvent</tt><a class="headerlink" href="#gozerlib.xmpp.event.XMPPEvent" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="gozerlib.eventbase.EventBase" class="reference external" href="../eventbase.html#gozerlib.eventbase.EventBase"><tt class="xref docutils literal"><span class="pre">gozerlib.eventbase.EventBase</span></tt></a></p>
<p>an XMPP event.</p>
<dl class="method">
<dt id="gozerlib.xmpp.event.XMPPEvent.parse">
<tt class="descname">parse</tt><big>(</big><em>request</em>, <em>response</em><big>)</big><a class="headerlink" href="#gozerlib.xmpp.event.XMPPEvent.parse" title="Permalink to this definition">¶</a></dt>
<dd>parse incoming request/response into a XMPPEvent.</dd></dl>

<dl class="method">
<dt id="gozerlib.xmpp.event.XMPPEvent.reply">
<tt class="descname">reply</tt><big>(</big><em>txt</em>, <em>resultlist=</em><span class="optional">[</span><span class="optional">]</span>, <em>nritems=False</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#gozerlib.xmpp.event.XMPPEvent.reply" title="Permalink to this definition">¶</a></dt>
<dd>reply with txt and optional resultlist. result lists can be 
passed on onto the events queues.</dd></dl>

<dl class="method">
<dt id="gozerlib.xmpp.event.XMPPEvent.write">
<tt class="descname">write</tt><big>(</big><em>txt</em><big>)</big><a class="headerlink" href="#gozerlib.xmpp.event.XMPPEvent.write" title="Permalink to this definition">¶</a></dt>
<dd>output txt to the user .. output IS escaped.</dd></dl>

</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/xmpp/event.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; an xmpp event. &quot;&quot;&quot;</span>

<span class="c">## gozerlib imports</span>

<span class="kn">from</span> <span class="nn">gozerlib.eventbase</span> <span class="kn">import</span> <span class="n">EventBase</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.xmpp</span> <span class="kn">import</span> <span class="n">stripped</span><span class="p">,</span> <span class="n">resource</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.auth</span> <span class="kn">import</span> <span class="n">checkuser</span>

<span class="c">## google imports</span>

<span class="kn">from</span> <span class="nn">google.appengine.api</span> <span class="kn">import</span> <span class="n">xmpp</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">cgi</span>
<span class="kn">import</span> <span class="nn">logging</span>

<span class="k">class</span> <span class="nc">XMPPEvent</span><span class="p">(</span><span class="n">EventBase</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; an XMPP event. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> 
        <span class="n">EventBase</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="s">&quot;xmpp&quot;</span>

    <span class="k">def</span> <span class="nf">__deepcopy__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; make a deepcopy of this XMPPEvent. &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">XMPPEvent</span><span class="p">()</span><span class="o">.</span><span class="n">copyin</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">txt</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; output data to user. txt is NOT escaped. &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">txt</span><span class="p">:</span>
            <span class="n">xmpp</span><span class="o">.</span><span class="n">send_message</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">userhost</span><span class="p">,</span> <span class="p">],</span> <span class="n">txt</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; parse incoming request/response into a XMPPEvent. &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">copyin</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">))</span>
        <span class="p">(</span><span class="n">userhost</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">nick</span><span class="p">)</span> <span class="o">=</span> <span class="n">checkuser</span><span class="p">(</span><span class="n">response</span><span class="p">,</span> <span class="n">request</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">userhost</span> <span class="o">=</span> <span class="n">stripped</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s">&#39;from&#39;</span><span class="p">])</span>

        <span class="k">if</span> <span class="n">user</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auth</span> <span class="o">=</span> <span class="n">user</span><span class="o">.</span><span class="n">email</span><span class="p">()</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;xmpp - auth is </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">userhost</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">resource</span> <span class="o">=</span> <span class="n">resource</span><span class="p">(</span><span class="bp">self</span><span class="p">[</span><span class="s">&#39;from&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">jid</span> <span class="o">=</span> <span class="bp">self</span><span class="p">[</span><span class="s">&#39;from&#39;</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">userhost</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">origtxt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">body</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">txt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">body</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">makeargs</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="nf">reply</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">txt</span><span class="p">,</span> <span class="n">resultlist</span><span class="o">=</span><span class="p">[],</span> <span class="n">nritems</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; reply with txt and optional resultlist. result lists can be </span>
<span class="sd">            passed on onto the events queues. </span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">checkqueues</span><span class="p">(</span><span class="n">resultlist</span><span class="p">):</span>
            <span class="k">return</span>

        <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">makeresponse</span><span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">resultlist</span><span class="p">,</span> <span class="n">nritems</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="p">(</span><span class="n">res1</span><span class="p">,</span> <span class="n">res2</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">less</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">res1</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">res2</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">res2</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">txt</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; output txt to the user .. output IS escaped. &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">txt</span><span class="p">:</span>
            <span class="n">xmpp</span><span class="o">.</span><span class="n">send_message</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">userhost</span><span class="p">,</span> <span class="p">],</span> <span class="n">cgi</span><span class="o">.</span><span class="n">escape</span><span class="p">(</span><span class="n">txt</span><span class="p">))</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.xmpp.event</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="bot.html"
                                  title="previous chapter">gozerlib.xmpp.bot</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="../../waveplugs/gcalc.html"
                                  title="next chapter">gcalc</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/xmpp/event.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../waveplugs/gcalc.html" title="gcalc"
             >next</a> |</li>
        <li class="right" >
          <a href="bot.html" title="gozerlib.xmpp.bot"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" >gozerlib.xmpp</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>